package com.own.business.irs.model;

import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * UserInfoModel
 *
 * @author chenxueli
 * @date 2023-07-02 13:30:21
 */
@Data
@NoArgsConstructor
public class UserInfoModel implements Serializable {

    @Schema(title = "用户在SSO分配的身份唯一号")
    private String userId;

    @Schema(title = "认证级别 1.匿名 2.实名 3.实人 （当认证级别为2或者3的时候实名信息才有效）")
    private String authLevel;

    @Schema(title = "实名信息 -- 用户真实姓名")
    private String username;

    @Schema(title = "实名信息 -- 证件号码（身份证）")
    private String idNum;

    @Schema(title = "实名信息 -- 性别 1男 2女")
    private String sex;

    @Schema(title = "实名信息 -- 民族(见国标GB3304-91)")
    private String nation;

    @Schema(title = "登录名")
    private String loginName;

    @Schema(title = "邮件")
    private String email;

    @Schema(title = "手机号码")
    private String mobile;

    @Schema(title = "邮编")
    private String postcode;

    @Schema(title = "CA证书KEY")
    private String cakey;

    @Schema(title = "生日")
    private String birthday;

    @Schema(title = "国籍")
    private String country;

    @Schema(title = "省籍")
    private String province;

    @Schema(title = "城市")
    private String city;

    @Schema(title = "办公地址")
    private String officeAddress;

    @Schema(title = "办公电话")
    private String officePhone;

    @Schema(title = "办公传真")
    private String officeFax;

    @Schema(title = "家庭电话")
    private String homePhone;

    @Schema(title = "家庭地址")
    private String homeAddress;

    @Schema(title = "用户激活状态  1激活，2未激活")
    private String enabled;

    @Schema(title = "头像地址")
    private String avatar;

    public UserInfoModel ofNormal(JSONObject jsonObject) {
        this.userId = jsonObject.getString("userid");
        this.authLevel = jsonObject.getString("authlevel");
        this.username = jsonObject.getString("username");
        this.idNum = jsonObject.getString("idnum");
        this.sex = jsonObject.getString("sex");
        this.nation = jsonObject.getString("nation");
        this.loginName = jsonObject.getString("loginname");
        this.email = jsonObject.getString("email");
        this.mobile = jsonObject.getString("mobile");
        this.postcode = jsonObject.getString("postcode");
        this.cakey = jsonObject.getString("cakey");
        this.birthday = jsonObject.getString("birthday");
        this.country = jsonObject.getString("country");
        this.province = jsonObject.getString("province");
        this.city = jsonObject.getString("city");
        this.officeAddress = jsonObject.getString("officeaddress");
        this.officePhone = jsonObject.getString("officephone");
        this.officeFax = jsonObject.getString("officefax");
        this.homePhone = jsonObject.getString("homephone");
        this.homeAddress = jsonObject.getString("homeaddress");
        this.enabled = jsonObject.getString("useable");
        this.avatar = jsonObject.getString("headpicture");
        return this;
    }

    public UserInfoModel ofWechat(JSONObject jsonObject) {
        this.userId = jsonObject.getString("userId");
        this.username = jsonObject.getString("userName");
        this.idNum = jsonObject.getString("idNo");
        this.sex = "MALE".equals(jsonObject.getString("gender")) ? "1" : "2";
        this.nation = jsonObject.getString("nation");
        this.loginName = jsonObject.getString("phone");
        this.email = jsonObject.getString("email");
        this.mobile = jsonObject.getString("phone");
        this.birthday = jsonObject.getString("birthday");
        return this;
    }

}
